﻿
Namespace Models.Providers

    Public Class SchoolClickRoleProvider
        Inherits RoleProvider

        Private DBFunctions As SchoolClickDB_Repositorio

        Public Sub New()
            DBFunctions = New SchoolClickDB_Repositorio
        End Sub

        Public Overrides Function RoleExists(roleName As String) As Boolean
            If String.IsNullOrEmpty(roleName.Trim) Then
                Return False
            End If

            Return DBFunctions.RolExist(roleName.Trim)
        End Function

        Public Overrides Function IsUserInRole(username As String, roleName As String) As Boolean
            If String.IsNullOrEmpty(username.Trim) OrElse String.IsNullOrEmpty(roleName.Trim) Then
                Return False
            End If

            Return DBFunctions.IsUser_in_Rol(username.Trim, roleName.Trim)
        End Function

        Public Overrides Function GetRolesForUser(username As String) As String()
            Dim sRol As String = String.Empty
            If String.IsNullOrEmpty(username.Trim) Then
                Throw New ApplicationException("No se pudieron verificar los roles del usuario debido a que el usuario esta en blanco")
            End If

            sRol = DBFunctions.GetRoles_For_User(username.Trim)

            Return New String() {sRol}
        End Function

#Region "METODOS NO IMPLEMENTADOS"
        Public Overrides Sub AddUsersToRoles(usernames() As String, roleNames() As String)
            Throw New NotImplementedException
        End Sub

        Public Overrides Property ApplicationName As String
            Get
                Return "SchoolClick"
            End Get
            Set(value As String)
                Throw New NotImplementedException
            End Set
        End Property

        Public Overrides Sub CreateRole(roleName As String)
            Throw New NotImplementedException
        End Sub

        Public Overrides Function DeleteRole(roleName As String, throwOnPopulatedRole As Boolean) As Boolean
            Throw New NotImplementedException
        End Function

        Public Overrides Function FindUsersInRole(roleName As String, usernameToMatch As String) As String()
            Throw New NotImplementedException
        End Function

        Public Overrides Function GetAllRoles() As String()
            Throw New NotImplementedException
        End Function

        Public Overrides Function GetUsersInRole(roleName As String) As String()
            Throw New NotImplementedException
        End Function

        Public Overrides Sub RemoveUsersFromRoles(usernames() As String, roleNames() As String)
            Throw New NotImplementedException
        End Sub
#End Region
    End Class
End Namespace